﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL.InfoConfig
{
    public  class DelegateDAL:DALBase
    {
        private static ObjectQuery<OutProcessShop> GetOutProcessShops()
        {
            return DataEntites.OutProcessShop.Include("Tb_OutShop_ProductCategory");
        }

        /// <summary>
        /// Get OutProcessShop list
        /// </summary>
        /// <returns></returns>
        public static List<OutProcessShop> GetOutProcessShopList()
        {
            List<OutProcessShop> list = new List<OutProcessShop>();
            foreach (var item in GetOutProcessShops())
	        {
        		 list.Add(item);
	        }
            return list;
        }
        /// <summary>
        ///  Get OutProcessShop object
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static OutProcessShop GetOutProcessShopObj(int id)
        {
            return DataEntites.OutProcessShop.First(o => o.OutShopId == id);
        }

        /// <summary>
        /// add OutProcessShop
        /// </summary>
        /// <param name="obj"></param>
        public static void Add(OutProcessShop obj)
        {
            DataEntites.AddToOutProcessShop(obj);
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Update OutProcessShop
        /// </summary>
        public static void Update()
        {
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// Delete OutProcessShop
        /// </summary>
        /// <param name="obj"></param>
        public static void Delete(OutProcessShop obj)
        {
            DataEntites.DeleteObject(obj);
            DataEntites.SaveChanges();
        }

        public static Tb_OutShop_ProductCategory GetOutShopProductCategory(int productId,int outshopId)
        {
            return DataEntites.Tb_OutShop_ProductCategory.FirstOrDefault(o => o.ProductId == productId && o.OutShopId == outshopId);
        }

        public static OutProcessShop GetOutProcessShopObj(string p)
        {
            return DataEntites.OutProcessShop.FirstOrDefault(o => o.OutShopName == p);
        }
    }
}
